//
//  KVNGourpbuyViewController.m
//  Test1
//
//  Created by KelvinYeung on 15/8/3.
//  Copyright (c) 2015年 KelvinYeung. All rights reserved.
//

#import "KVNGroupbuyViewController.h"
#define FILTER_CELL_HEIGHT 40
#define FILTER_INDUST_CAT 1
#define FILTER_TYPE_CAT 2
#define FILTER_STATUS_CAT 3
#define FIlTER_MORE_CAT 4

#define TABLE_VIEW_CELL_HEIGHT 90;

#define ANIMATION_DURATION 0.1

@interface KVNGroupbuyViewController ()

@property BOOL isLoading;
//列表
@property UITableView *tableView;
@property NSMutableArray *groupbuyArray;
@property NSInteger currentPage;
@property NSMutableDictionary *queryParam;
//筛选bar的四个按钮
@property UIButton *button1;
@property UIButton *button2;
@property UIButton *button3;
@property UIButton *button4;

//筛选面板约束
@property UIView *filterMask;
@property NSLayoutConstraint *filterPannelConstraintTop;
@property NSLayoutConstraint *filterPannelConstraintLeft;
@property NSLayoutConstraint *filterPannelConstraintBottom;
@property NSLayoutConstraint *filterPannelConstraintRight;
@property NSLayoutConstraint *filterPannelConstraintHeight;
@property BOOL isFilterPannelShow;
@property UIImageView * filterPannelIndicator;
@property NSLayoutConstraint * filterPannelIndicatorConstraintCenterX;
//筛选条件
@property int currentPannelInex;
@property int selectedIndustId;
@property int selectedTypeId;
@property int selectedStatusId;

//行业类型
@property UITableView *filterPannelView;
@property NSMutableArray *industryCategorysArray;
//类型
@property NSMutableArray *typeCategorysArray;//类型类别
@property NSArray *houseStatusArray;//状态 已开盘、未开盘、已开业、未开业、 status; //状态 1：已开盘 2：未开盘 3：已开业 4：未开业 （另外：在售价/租金中 待售、待租 也应该传此参数status=2 对应未开盘）

//更多选择条件
@property UIView *filterMorePannelView;
@property UITableView * filterMorePannelTableView1;
@property UITableView * filterMorePannelTableView2;
@property NSArray * filterMoreArray;
@property NSInteger filterMoreArraySelectedIndex;

@property NSArray * buildingAreaArray;//体量 minBuildingArea  maxBuildingArea;
@property NSMutableArray * locationCategorysArray; //特殊区位；/houseCategory/locationCategorys.do
@property NSArray * modelAreaArray; //户型 minModelArea; //户型min maxModelArea; //户型max
@property NSArray * buyPriceArray; //售价 minBuyPrice; //售价min（团购使用）maxBuyPrice; //售价max（团购使用）
@property NSArray * rentPriceArray; //租金 minRentPrice; //租金min（团租使用） maxRentPrice; //租金max（团租使用）
@property NSMutableArray * projectNatureCategorysArray; //项目性质 /houseCategory/natureCategorys.do projectNatureCategoryId; //项目性质ID


//选择的条件
@property NSInteger industCatSelectedIndex;//行业类型
@property NSInteger typeCategorysSelectedIndex;//类型
@property NSInteger statusCategorysSelectedIndex;//状态
@property NSInteger buildingAreaSelectedIndex;
@property NSInteger locationCategorysSelectedIndex;
@property NSInteger buyPriceSelectedIndex;
@property NSInteger modelAreaSelectedIndex;
@property NSInteger rentPriceArraySelectedIndex;
@property NSInteger projectNatureSelectedIndex;

//footerView
@property UIView *footerView;
@property UILabel *footerViewLabel;
@property UIActivityIndicatorView * footerViewAcitiviyIndicatorView;

@end

@implementation KVNGroupbuyViewController
@synthesize filterPannelView;
@synthesize filterMask;
@synthesize filterMorePannelView;
@synthesize filterMorePannelTableView1;
@synthesize filterMorePannelTableView2;
@synthesize button1;
@synthesize button2;
@synthesize button3;
@synthesize button4;


- (void)viewDidLoad {
    [super viewDidLoad];
    
   
    //初始筛选数据
    [self initFilterArrays];
    
    
    CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
    
    
    //搜索栏
    UISearchBar *searchBar = [[UISearchBar alloc] init];
    searchBar.placeholder = @"楼盘名/开发商";
    [searchBar setSearchBarStyle:UISearchBarStyleDefault];
    
    //去除searchbar背景
    for (UIView *view in searchBar.subviews) {
        // for before iOS7.0
        if ([view isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
            [view removeFromSuperview];
            break;
        }
        // for later iOS7.0(include)
        
        if ([view isKindOfClass:NSClassFromString(@"UIView")] && view.subviews.count > 0) {
            [[view.subviews objectAtIndex:0] removeFromSuperview];
            break;
        }
        
    }
    UIView *searchBarview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 500, 30)];
    [searchBarview addSubview:searchBar];
    //[view setBackgroundColor:[UIColor purpleColor]];
    searchBar.translatesAutoresizingMaskIntoConstraints = NO;
    
    
    
    [searchBarview addConstraint:[NSLayoutConstraint constraintWithItem:searchBar attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:searchBarview attribute:NSLayoutAttributeWidth multiplier:1 constant:0]];
    [searchBarview addConstraint:[NSLayoutConstraint constraintWithItem:searchBar attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:searchBarview attribute:NSLayoutAttributeHeight multiplier:1 constant:0]];
    [searchBarview addConstraint:[NSLayoutConstraint constraintWithItem:searchBar attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:searchBarview attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [searchBarview addConstraint:[NSLayoutConstraint constraintWithItem:searchBar attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:searchBarview attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
    
   
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"地图" style:UIBarButtonItemStylePlain target:nil action:nil];
    
    //导航栏
    self.navigationItem.titleView =searchBarview;
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
    

    
    
    
    //筛选按钮------------------------------------------
    UIView *filterBar = [[UIView alloc] initWithFrame:CGRectMake(0, 64, appFrame.size.width, 35)];
    [filterBar setBackgroundColor:[UIColor colorWithWhite:0.95 alpha:1]];
    filterBar.layer.borderColor = [[UIColor colorWithWhite:0.8 alpha:1] CGColor];
    filterBar.layer.borderWidth = 0.3;
    [self.view addSubview:filterBar];
    //行业按钮
    button1 = [UIButton buttonWithType:UIButtonTypeSystem];
    button1.tag = FILTER_INDUST_CAT;
    [button1 setTitle:@"行业" forState:UIControlStateNormal];
    button1.tintColor = [UIColor blackColor];
    [button1 setImage:[UIImage imageNamed:@"arrow_down_gray"] forState:UIControlStateNormal];
    [button1.imageView setFrame:CGRectMake(0, 0, 5, 5)];
    [button1.imageView setTintColor:[UIColor purpleColor]];
    button1.imageEdgeInsets = UIEdgeInsetsMake(10, appFrame.size.width*0.25*0.77, 10,appFrame.size.width*0.25*0.1);
    button1.titleEdgeInsets = UIEdgeInsetsMake(0, -appFrame.size.width*0.25*0.5, 0, 0);
    [button1.imageView setClipsToBounds:NO];
    button1.frame = CGRectMake(0, 0, appFrame.size.width*0.25, 35);
    
    [filterBar addSubview:button1];
    [button1 addTarget:self action:@selector(filterBarClick:) forControlEvents:UIControlEventTouchUpInside];
    
    //分隔线
    //UIImageView *filterBarSeperator = [[UIImageView alloc] initWithFrame:CGRectMake(appFrame.size.width*0.25, 0, 5, 30)];
    //UIImage *filterBarSeperatorImage = [UIImage imageNamed:@"arrow_slice"];
    //filterBarSeperator.image = filterBarSeperatorImage;
    //[filterBar addSubview:filterBarSeperator];
    
    UIView *filterBarSeperator1 = [[UIView alloc] initWithFrame:CGRectMake(appFrame.size.width*0.25, 8, 0.3, 19)];
    filterBarSeperator1.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1];
    [filterBar addSubview:filterBarSeperator1];
    
    
    
    //类型按钮
    button2 = [UIButton buttonWithType:UIButtonTypeSystem];
    button2.tag = FILTER_TYPE_CAT;
    [button2 setTitle:@"类型" forState:UIControlStateNormal];
    button2.tintColor = [UIColor blackColor];
    [button2 setImage:[UIImage imageNamed:@"arrow_down_gray"] forState:UIControlStateNormal];
    [button2.imageView setFrame:CGRectMake(0, 0, 5, 5)];
    [button2.imageView setTintColor:[UIColor purpleColor]];
    button2.imageEdgeInsets = UIEdgeInsetsMake(10, appFrame.size.width*0.25*0.77, 10,appFrame.size.width*0.25*0.1);
    button2.titleEdgeInsets = UIEdgeInsetsMake(0, -appFrame.size.width*0.25*0.5, 0, 0);
    [button2.imageView setClipsToBounds:NO];
    button2.frame = CGRectMake(appFrame.size.width*0.25, 0, appFrame.size.width*0.25, 35);
    [filterBar addSubview:button2];

    [button2 addTarget:self action:@selector(filterBarClick:) forControlEvents:UIControlEventTouchUpInside];
    
    //分隔线
    
    UIView *filterBarSeperator2 = [[UIView alloc] initWithFrame:CGRectMake(appFrame.size.width*0.5, 8, 0.3, 19)];
    filterBarSeperator2.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1];
    [filterBar addSubview:filterBarSeperator2];
    
    //状态按钮
    button3 = [UIButton buttonWithType:UIButtonTypeSystem];
    [button3 setTitle:@"状态" forState:UIControlStateNormal];
    button3.tintColor = [UIColor blackColor];
    [button3 setImage:[UIImage imageNamed:@"arrow_down_gray"] forState:UIControlStateNormal];
    [button3.imageView setFrame:CGRectMake(0, 0, 5, 5)];
    [button3.imageView setTintColor:[UIColor purpleColor]];
    button3.imageEdgeInsets = UIEdgeInsetsMake(10, appFrame.size.width*0.25*0.77, 10,appFrame.size.width*0.25*0.1);
    button3.titleEdgeInsets = UIEdgeInsetsMake(0, -appFrame.size.width*0.25*0.5, 0, 0);
    [button3.imageView setClipsToBounds:NO];
    button3.frame = CGRectMake(appFrame.size.width*0.5, 0, appFrame.size.width*0.25, 35);
    [filterBar addSubview:button3];
    button3.tag = FILTER_STATUS_CAT;
    [button3 addTarget:self action:@selector(filterBarClick:) forControlEvents:UIControlEventTouchUpInside];
    
    //分隔线
    
    UIView *filterBarSeperator3 = [[UIView alloc] initWithFrame:CGRectMake(appFrame.size.width*0.75, 8, 0.3, 19)];
    filterBarSeperator3.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1];
    [filterBar addSubview:filterBarSeperator3];
    
    //更多
    button4 = [UIButton buttonWithType:UIButtonTypeSystem];
    [button4 setTitle:@"更多" forState:UIControlStateNormal];
    button4.tintColor = [UIColor blackColor];
    [button4 setImage:[UIImage imageNamed:@"arrow_down_gray"] forState:UIControlStateNormal];
    [button4.imageView setFrame:CGRectMake(0, 0, 5, 5)];
    [button4.imageView setTintColor:[UIColor purpleColor]];
    button4.imageEdgeInsets = UIEdgeInsetsMake(10, appFrame.size.width*0.25*0.77, 10,appFrame.size.width*0.25*0.1);
    button4.titleEdgeInsets = UIEdgeInsetsMake(0, -appFrame.size.width*0.25*0.5, 0, 0);
    [button4.imageView setClipsToBounds:NO];
    button4.frame = CGRectMake(appFrame.size.width*0.75, 0, appFrame.size.width*0.25, 35);
    [filterBar addSubview:button4];
    button4.tag = FIlTER_MORE_CAT;
    [button4 addTarget:self action:@selector(filterBarClick:) forControlEvents:UIControlEventTouchUpInside];
 
    
    //行业下拉列表
   // UIViewController *testController = [[UIViewController alloc] init];
    
    //UIPopoverController *popoverController1 = [[UIPopoverController alloc] initWithContentViewController:testController];
    //UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
    //testView.backgroundColor = [UIColor purpleColor];
    //[popoverController1.contentViewController.view addSubview:testView];
    
    //[popoverController1 presentPopoverFromRect:CGRectMake(0, 0, 20, 35) inView:button1 permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    
    //popoverController1.delegate = self;
    //self.preferredContentSize = CGSizeMake(480, 200);
    
    
    
    //列表
    _tableView  = [[UITableView alloc]init];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    _tableView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:_tableView];
    _tableView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
    //列表在filterView之下，bottomg与self.view的bottom对齐
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:filterBar attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1 constant:0]];

    _tableView.tag = 1;
    _tableView.delegate = self;
    _tableView.dataSource = self;

    
    //footer
    _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, appFrame.size.width, 30)];
    [_tableView setTableFooterView:_footerView];
    //_footerView.backgroundColor = [UIColor purpleColor];
    _footerViewLabel = [[UILabel alloc] init];
    [_footerView addSubview:_footerViewLabel];
    
    _footerViewLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [_footerView addConstraint:[NSLayoutConstraint constraintWithItem:_footerViewLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_footerView attribute:NSLayoutAttributeCenterX multiplier:1 constant:1]];
    [_footerView addConstraint:[NSLayoutConstraint constraintWithItem:_footerViewLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:_footerView attribute:NSLayoutAttributeCenterY multiplier:1 constant:1]];
    
    
    _footerViewAcitiviyIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [_footerView addSubview:_footerViewAcitiviyIndicatorView];
    _footerViewAcitiviyIndicatorView.translatesAutoresizingMaskIntoConstraints = NO;
    [_footerView addConstraint:[NSLayoutConstraint constraintWithItem:_footerViewAcitiviyIndicatorView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:_footerViewLabel attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
    [_footerView addConstraint:[NSLayoutConstraint constraintWithItem:_footerViewAcitiviyIndicatorView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:_footerView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
    _footerViewAcitiviyIndicatorView.hidesWhenStopped = YES;
    [_footerViewAcitiviyIndicatorView startAnimating];
    
    _footerViewLabel.text = @"上拉加载更多数据!";
    _footerViewLabel.textColor = [UIColor grayColor];
    _footerViewLabel.font = [UIFont systemFontOfSize:12];
    
    //筛选条件

    filterMask = [[UIView alloc] init];
    [self.view addSubview:filterMask];
    filterMask.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.7];
    //[filterMask setHidden:YES];
    filterMask.translatesAutoresizingMaskIntoConstraints = NO;
    
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:filterMask attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:filterBar attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:filterMask attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:filterMask attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:filterMask attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1 constant:0]];
    
    
    filterPannelView = [[UITableView alloc] init];
    [self.view addSubview:filterPannelView];
    filterPannelView.translatesAutoresizingMaskIntoConstraints = NO;
    
    _filterPannelConstraintTop = [NSLayoutConstraint constraintWithItem:filterPannelView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:filterBar attribute:NSLayoutAttributeBottom multiplier:1 constant:10];

    _filterPannelConstraintLeft = [NSLayoutConstraint constraintWithItem:filterPannelView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
    
    _filterPannelConstraintRight = [NSLayoutConstraint constraintWithItem:filterPannelView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1 constant:0];
    _filterPannelConstraintBottom = [NSLayoutConstraint constraintWithItem:filterPannelView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationLessThanOrEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
    
    _filterPannelConstraintHeight = [NSLayoutConstraint constraintWithItem:filterPannelView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:0];
    
    _filterPannelConstraintHeight.priority = UILayoutPriorityDefaultHigh;
    
    
    [self.view addConstraints:@[_filterPannelConstraintTop,_filterPannelConstraintLeft,_filterPannelConstraintBottom,_filterPannelConstraintRight,_filterPannelConstraintHeight]];
    
    
    filterPannelView.tag = 2;
    filterPannelView.delegate = self;
    filterPannelView.dataSource = self;
    filterPannelView.hidden =YES;
    filterMask.hidden = YES;
    
    
    
    //更多筛选条件
    filterMorePannelView = [[UIView alloc] init];
    filterMorePannelTableView1 = [[UITableView alloc] init];
    filterMorePannelTableView2 = [[UITableView alloc] init];
    [filterMorePannelView setHidden:YES];
    [self.view addSubview:filterMorePannelView];
    filterMorePannelTableView1.tag = 3;
    filterMorePannelTableView2.tag = 4;
    filterMorePannelTableView1.delegate = self;
    filterMorePannelTableView1.dataSource = self;
    filterMorePannelTableView2.delegate = self;
    filterMorePannelTableView2.dataSource = self;
    [filterMorePannelView addSubview:filterMorePannelTableView1];
    [filterMorePannelView addSubview:filterMorePannelTableView2];
    filterMorePannelView.backgroundColor = [UIColor whiteColor];
    filterMorePannelTableView1.backgroundColor = [UIColor whiteColor];
    filterMorePannelView.layer.borderWidth = 0.3;
    filterMorePannelView.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    filterMorePannelTableView2.layer.borderColor =[[UIColor lightGrayColor] CGColor];;
    filterMorePannelTableView2.layer.borderWidth = 0.3;
    //定位
    filterMorePannelView.translatesAutoresizingMaskIntoConstraints = NO;
    filterMorePannelTableView1.translatesAutoresizingMaskIntoConstraints = NO;
    filterMorePannelTableView2.translatesAutoresizingMaskIntoConstraints = NO;

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:filterBar attribute:NSLayoutAttributeBottom multiplier:1 constant:10]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1 constant:0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationLessThanOrEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    
    NSLayoutConstraint *filterMorePannelConstraintHeight = [NSLayoutConstraint constraintWithItem:filterMorePannelView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:_filterMoreArray.count * FILTER_CELL_HEIGHT+64];
    filterMorePannelConstraintHeight.priority = UILayoutPriorityDefaultHigh;

    [self.view addConstraint:filterMorePannelConstraintHeight];
    
    //filterTableView1
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelTableView1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:filterMorePannelView attribute:NSLayoutAttributeTop multiplier:1 constant:0]];
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelTableView1 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:filterMorePannelView attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelTableView1 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:filterMorePannelView attribute:NSLayoutAttributeRight multiplier:1 constant:0]];
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelTableView1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationLessThanOrEqual toItem:filterMorePannelView attribute:NSLayoutAttributeBottom multiplier:1 constant:-64]];
    
    NSLayoutConstraint *filterMorePannelTableView1ConstraintHeight = [NSLayoutConstraint constraintWithItem:filterMorePannelTableView1 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:_filterMoreArray.count * FILTER_CELL_HEIGHT];
    filterMorePannelTableView1ConstraintHeight.priority = UILayoutPriorityDefaultHigh;
    [filterMorePannelView addConstraint:filterMorePannelTableView1ConstraintHeight];
    
    
    
    //filterView2
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelTableView2 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:filterMorePannelTableView1 attribute:NSLayoutAttributeTop multiplier:1 constant:0]];
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelTableView2 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:filterMorePannelTableView1 attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelTableView2 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:filterMorePannelTableView1 attribute:NSLayoutAttributeRight multiplier:1 constant:0]];
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelTableView2 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:filterMorePannelTableView1 attribute:NSLayoutAttributeLeft multiplier:1 constant:100]];
    
    
   
    //filter按钮
    UIButton *filterMorePannelResetBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    UIButton *filterMorePannelOkBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [filterMorePannelView addSubview:filterMorePannelResetBtn];
    [filterMorePannelView addSubview:filterMorePannelOkBtn];
    [filterMorePannelResetBtn setTitle:@"重置" forState:UIControlStateNormal];
    [filterMorePannelOkBtn setTitle:@"确定" forState:UIControlStateNormal];
    [filterMorePannelResetBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [filterMorePannelOkBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    filterMorePannelResetBtn.backgroundColor = [UIColor whiteColor];
    filterMorePannelOkBtn.backgroundColor = [UIColor whiteColor];
    filterMorePannelResetBtn.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    filterMorePannelOkBtn.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    filterMorePannelResetBtn.layer.borderWidth = 0.3;
    filterMorePannelOkBtn.layer.borderWidth =0.3;
    filterMorePannelResetBtn.layer.cornerRadius = 5;
    filterMorePannelOkBtn.layer.cornerRadius = 5;
    
    
    filterMorePannelResetBtn.translatesAutoresizingMaskIntoConstraints = NO;
    filterMorePannelOkBtn.translatesAutoresizingMaskIntoConstraints = NO;
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelResetBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:filterMorePannelView attribute:NSLayoutAttributeBottom multiplier:1 constant:-10]];
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelResetBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:filterMorePannelView attribute:NSLayoutAttributeLeft multiplier:1 constant:10]];
    
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelOkBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:filterMorePannelView attribute:NSLayoutAttributeBottom multiplier:1 constant:-10]];
    
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelOkBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:filterMorePannelResetBtn attribute:NSLayoutAttributeRight multiplier:1 constant:10]];
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelOkBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:filterMorePannelView attribute:NSLayoutAttributeRight multiplier:1 constant:-10]];
    [filterMorePannelView addConstraint:[NSLayoutConstraint constraintWithItem:filterMorePannelOkBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:filterMorePannelResetBtn attribute:NSLayoutAttributeWidth multiplier:1 constant:0]];
    
    
    [filterMorePannelOkBtn addTarget:self action:@selector(filterMoreOkBtnClick:)  forControlEvents:UIControlEventTouchUpInside];
    [filterMorePannelResetBtn addTarget:self action:@selector(filterMoreResetBtnClick:)  forControlEvents:UIControlEventTouchUpInside];
    
    //筛选面板指示器
    _filterPannelIndicator = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_up_white"]];
    [self.view addSubview:_filterPannelIndicator];
    _filterPannelIndicator.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_filterPannelIndicator attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:filterBar attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_filterPannelIndicator attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:filterPannelView attribute:NSLayoutAttributeTop multiplier:1 constant:4]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_filterPannelIndicator attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:30]];
    _filterPannelIndicatorConstraintCenterX = [NSLayoutConstraint constraintWithItem:_filterPannelIndicator attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:button1 attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    [self.view addConstraint:_filterPannelIndicatorConstraintCenterX];
    [_filterPannelIndicator setHidden:YES];
    
    
    
    //数据请求
    [self initData];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


#pragma mark - 初始化筛选数组
- (void) initFilterArrays{

    /*
     {"pageNumber":1,"pageSize":10,"params":
     {"maxRentPrice":1000,"maxBuyPrice":1000,
     "status":1,
     "industryCategoryId":2,
     
     "maxBuildingArea":500,
     "minBuildingArea":5,
     
     "maxPrice":10000,"minPrcie":100,
     
     "projectNatureCategoryId":1,
     "specialLocationCategoryId":1,
     
     "minModelArea":5,"maxModelArea":500,
     
     "activityCategoryId":3,
     "typeCategoryId":2}}
     */
    
    _filterMoreArray =  @[@"不限",@"体量",@"特殊区位",@"售价",@"户型",@"租金",@"项目性质"];
    
    _buildingAreaArray = @[@{@"name":@"不限",@"minBuildingArea":@0,@"maxBuildingArea":@99999999}
                        ,@{@"name":@"5万m2以下",@"minBuildingArea":@0,@"maxBuildingArea":@50000}
                        ,@{@"name":@"5万m2-10万m2",@"minBuildingArea":@50000,@"maxBuildingArea":@100000}
                        ,@{@"name":@"10万m2-20万m2",@"minBuildingArea":@100000,@"maxBuildingArea":@200000}
                        ,@{@"name":@"20万m2以上",@"minBuildingArea":@200000,@"maxBuildingArea":@99999999}];
    
    _modelAreaArray = @[@{@"name":@"不限",@"minModelArea":@0,@"maxModelArea":@999999},
                        @{@"name":@"50m2以下",@"minModelArea":@0,@"maxModelArea":@50},
                        @{@"name":@"50-150m2",@"minModelArea":@50,@"maxModelArea":@150},
                        @{@"name":@"150-300m2",@"minModelArea":@150,@"maxModelArea":@300},
                        @{@"name":@"300m2以上",@"minModelArea":@300,@"maxModelArea":@999999}
                        ];
    
    _buyPriceArray = @[@{@"name":@"不限",@"minPrice":@0,@"maxPrice":@999999}
                    ,@{@"name":@"待售",@"minPrice":@0,@"maxPrice":@0}
                    ,@{@"name":@"5000元/m2以下",@"minPrice":@0,@"maxPrice":@5000}
                    ,@{@"name":@"5000-15000元/m2",@"minPrice":@5000,@"maxPrice":@15000}
                    ,@{@"name":@"15000-30000元/m2",@"minPrice":@15000,@"maxPrice":@30000}
                    ,@{@"name":@"30000元/m2以上",@"minPrice":@30000,@"maxPrice":@9999999}];
    
    _houseStatusArray = @[@"不限",@"已开盘",@"未开盘",@"已开业",@"未开业"];
    
    
}




#pragma  mark - 筛选按钮点击
- (void) filterBarClick:(id)sender{

    if (_industryCategorysArray.count<=0) {
        return;
    }
    
    switch (((UIButton*)sender).tag) {
        case FILTER_INDUST_CAT:
            
            //批示器移到当前位置
            [self.view removeConstraint:_filterPannelIndicatorConstraintCenterX];
            
            _filterPannelIndicatorConstraintCenterX = [NSLayoutConstraint constraintWithItem:_filterPannelIndicator attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:button1 attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
            [self.view addConstraint:_filterPannelIndicatorConstraintCenterX];
            [_filterPannelIndicator setHidden:NO];
            
            if (!filterMorePannelView.isHidden) {
                //先把filterMorePannelView隐藏
                [self.view layoutIfNeeded];
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    for (NSLayoutConstraint *constraint in self.view.constraints){
                        if( constraint.firstItem == filterMorePannelView &&
                           constraint.firstAttribute == NSLayoutAttributeHeight){
                            constraint.constant = 0;
                        }
                        
                    }
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {
        
                    [filterMorePannelView setHidden:YES];
                    [filterPannelView setHidden:NO];
                    _filterPannelConstraintHeight.constant = 0;
                    _currentPannelInex = FILTER_INDUST_CAT;
                    [filterPannelView reloadData];
                    [self.view layoutIfNeeded];
                    [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                        _filterPannelConstraintHeight.constant = _industryCategorysArray.count * FILTER_CELL_HEIGHT;
                        [self.view layoutIfNeeded];
                    } completion:^(BOOL finished) {
                        [filterMask setHidden:NO];
                    }];
                    
                    
                }];
                
            }
            else if(filterPannelView.isHidden){
                _currentPannelInex = FILTER_INDUST_CAT;
                [filterPannelView reloadData];
                [filterPannelView setHidden:NO];
                _filterPannelConstraintHeight.constant = 0;
                
                [self.view layoutIfNeeded];
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    _filterPannelConstraintHeight.constant = _industryCategorysArray.count * FILTER_CELL_HEIGHT;
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {
                    [filterMask setHidden:NO];
                }];
                
                
            }else if(_currentPannelInex != FILTER_INDUST_CAT){
                
                //先隐后显
                [self.view layoutIfNeeded];
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    _filterPannelConstraintHeight.constant = 0;
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {
                    [filterPannelView setHidden:NO];
                    _filterPannelConstraintHeight.constant = 0;
                    _currentPannelInex = FILTER_INDUST_CAT;
                    [filterPannelView reloadData];
                    [self.view layoutIfNeeded];
                    [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                        _filterPannelConstraintHeight.constant = _industryCategorysArray.count * FILTER_CELL_HEIGHT;
                        [self.view layoutIfNeeded];
                    } completion:^(BOOL finished) {
                        [filterMask setHidden:NO];
                    }];
                    
                }];
                
                
                
            }else{
                [filterMask setHidden:YES];
                _filterPannelConstraintHeight.constant = _industryCategorysArray.count * FILTER_CELL_HEIGHT;
                [self.view layoutIfNeeded];
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    _filterPannelConstraintHeight.constant = 0;
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {
                    [_filterPannelIndicator setHidden:YES];
                    [filterPannelView setHidden:YES];
                }];
            
            
            }
            
            break;
            
            
            
            
        case FILTER_TYPE_CAT:
            
            //批示器移到当前位置
            [self.view removeConstraint:_filterPannelIndicatorConstraintCenterX];
            
            _filterPannelIndicatorConstraintCenterX = [NSLayoutConstraint constraintWithItem:_filterPannelIndicator attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:button2 attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
            [self.view addConstraint:_filterPannelIndicatorConstraintCenterX];
            [_filterPannelIndicator setHidden:NO];
            
            
            
            if (!filterMorePannelView.isHidden) {
                //先把filterMorePannelView隐藏
                [self.view layoutIfNeeded];
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    for (NSLayoutConstraint *constraint in self.view.constraints){
                        if( constraint.firstItem == filterMorePannelView &&
                           constraint.firstAttribute == NSLayoutAttributeHeight){
                            constraint.constant = 0;
                        }
                        
                    }
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {
                    [filterMorePannelView setHidden:YES];
                    [filterPannelView setHidden:NO];
                    _filterPannelConstraintHeight.constant = 0;
                    _currentPannelInex = FILTER_TYPE_CAT;
                    [filterPannelView reloadData];
                    [self.view layoutIfNeeded];
                    [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                        _filterPannelConstraintHeight.constant = _typeCategorysArray.count * FILTER_CELL_HEIGHT;
                        [self.view layoutIfNeeded];
                    } completion:^(BOOL finished) {
                        [filterMask setHidden:NO];
                    }];
                    
                    
                }];
                
            }
            else if(filterPannelView.isHidden){
                _currentPannelInex = FILTER_TYPE_CAT;
                [filterPannelView reloadData];
                [filterPannelView setHidden:NO];
                _filterPannelConstraintHeight.constant = 0;
                
                [self.view layoutIfNeeded];
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    _filterPannelConstraintHeight.constant = _typeCategorysArray.count * FILTER_CELL_HEIGHT;
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {
                    [filterMask setHidden:NO];
                }];
                
                
            }else if(_currentPannelInex != FILTER_TYPE_CAT){
                
                //先隐后显
                [self.view layoutIfNeeded];
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    _filterPannelConstraintHeight.constant = 0;
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {
                    [filterPannelView setHidden:NO];
                    _filterPannelConstraintHeight.constant = 0;
                    _currentPannelInex = FILTER_TYPE_CAT;
                    [filterPannelView reloadData];
                    [self.view layoutIfNeeded];
                    [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                        _filterPannelConstraintHeight.constant = _typeCategorysArray.count * FILTER_CELL_HEIGHT;
                        [self.view layoutIfNeeded];
                    } completion:^(BOOL finished) {
                        [filterMask setHidden:NO];
                    }];
                    
                }];
                
                
                
            }else{
                [filterMask setHidden:YES];
                _filterPannelConstraintHeight.constant = _typeCategorysArray.count * FILTER_CELL_HEIGHT;
                [self.view layoutIfNeeded];
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    _filterPannelConstraintHeight.constant = 0;
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {
                    [_filterPannelIndicator setHidden:YES];
                    [filterPannelView setHidden:YES];
                }];
                
                
            }
        break;
        case FILTER_STATUS_CAT:
            //批示器移到当前位置
            [self.view removeConstraint:_filterPannelIndicatorConstraintCenterX];
            
            _filterPannelIndicatorConstraintCenterX = [NSLayoutConstraint constraintWithItem:_filterPannelIndicator attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:button3 attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
            [self.view addConstraint:_filterPannelIndicatorConstraintCenterX];
            [_filterPannelIndicator setHidden:NO];
            
            if (!filterMorePannelView.isHidden) {
                //先把filterMorePannelView隐藏
                [self.view layoutIfNeeded];
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    for (NSLayoutConstraint *constraint in self.view.constraints){
                        if( constraint.firstItem == filterMorePannelView &&
                           constraint.firstAttribute == NSLayoutAttributeHeight){
                            constraint.constant = 0;
                        }
                        
                    }
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {
                    [filterMorePannelView setHidden:YES];
                    [filterPannelView setHidden:NO];
                    _filterPannelConstraintHeight.constant = 0;
                    _currentPannelInex = FILTER_STATUS_CAT;
                    [filterPannelView reloadData];
                    [self.view layoutIfNeeded];
                    [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                        _filterPannelConstraintHeight.constant = _houseStatusArray.count * FILTER_CELL_HEIGHT;
                        [self.view layoutIfNeeded];
                    } completion:^(BOOL finished) {
                        [filterMask setHidden:NO];
                    }];
                    
                    
                }];
                
            }
            else if(filterPannelView.isHidden){
                _currentPannelInex = FILTER_STATUS_CAT;
                [filterPannelView reloadData];
                [filterPannelView setHidden:NO];
                _filterPannelConstraintHeight.constant = 0;
                
                [self.view layoutIfNeeded];
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    _filterPannelConstraintHeight.constant = _houseStatusArray.count * FILTER_CELL_HEIGHT;
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {
                    [filterMask setHidden:NO];
                }];
                
                
            }else if(_currentPannelInex != FILTER_STATUS_CAT){
                
                //先隐后显
                [self.view layoutIfNeeded];
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    _filterPannelConstraintHeight.constant = 0;
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {
                    [filterPannelView setHidden:NO];
                    _filterPannelConstraintHeight.constant = 0;
                    _currentPannelInex = FILTER_STATUS_CAT;
                    [filterPannelView reloadData];
                    [self.view layoutIfNeeded];
                    [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                        _filterPannelConstraintHeight.constant = _houseStatusArray.count * FILTER_CELL_HEIGHT;
                        [self.view layoutIfNeeded];
                    } completion:^(BOOL finished) {
                        [filterMask setHidden:NO];
                    }];
                    
                }];
                
                
                
            }else{
                [filterMask setHidden:YES];
                _filterPannelConstraintHeight.constant = _typeCategorysArray.count * FILTER_CELL_HEIGHT;
                [self.view layoutIfNeeded];
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    _filterPannelConstraintHeight.constant = 0;
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {
                    [_filterPannelIndicator setHidden:YES];
                    [filterPannelView setHidden:YES];
                }];
                
                
            }
            
            
            break;
        case FIlTER_MORE_CAT:
            //批示器移到当前位置
            [self.view removeConstraint:_filterPannelIndicatorConstraintCenterX];
            
            _filterPannelIndicatorConstraintCenterX = [NSLayoutConstraint constraintWithItem:_filterPannelIndicator attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:button4 attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
            [self.view addConstraint:_filterPannelIndicatorConstraintCenterX];
            [_filterPannelIndicator setHidden:NO];
            
            
            if(!filterPannelView.isHidden){
            [self.view layoutIfNeeded];
            [UIView animateWithDuration:ANIMATION_DURATION animations:^{
               
                _filterPannelConstraintHeight.constant=0;
                [self.view layoutIfNeeded];
                
            } completion:^(BOOL finished) {
                [filterPannelView setHidden:YES];
                [filterMorePannelView setHidden:NO];
                for (NSLayoutConstraint *constraint in self.view.constraints){
                    if( constraint.firstItem == filterMorePannelView &&
                       constraint.firstAttribute == NSLayoutAttributeHeight){
                        constraint.constant = _filterMoreArray.count * FILTER_CELL_HEIGHT + 64;
                    }
                
                }
                [self.view layoutIfNeeded];
            }];
                
            
            }else if(filterMorePannelView.isHidden){
                [filterMorePannelView setHidden: NO];
                [filterMask setHidden:NO];
                for (NSLayoutConstraint *constraint in self.view.constraints){
                    if( constraint.firstItem == filterMorePannelView &&
                       constraint.firstAttribute == NSLayoutAttributeHeight){
                        constraint.constant = 0;
                    }
                    
                }
                [self.view layoutIfNeeded];
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    for (NSLayoutConstraint *constraint in self.view.constraints){
                        if( constraint.firstItem == filterMorePannelView &&
                           constraint.firstAttribute == NSLayoutAttributeHeight){
                            constraint.constant = _filterMoreArray.count * FILTER_CELL_HEIGHT + 64;
                        }
                        
                    }
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {

                }];
                
                
            
            }else {
                
                [self.view layoutIfNeeded];
                
                [UIView animateWithDuration:ANIMATION_DURATION animations:^{
                    for (NSLayoutConstraint *constraint in self.view.constraints){
                        if( constraint.firstItem == filterMorePannelView &&
                           constraint.firstAttribute == NSLayoutAttributeHeight){
                            constraint.constant = 0;
                        }
                        
                    }
                    [self.view layoutIfNeeded];
                } completion:^(BOOL finished) {
                    [_filterPannelIndicator setHidden:YES];
                    [filterMorePannelView setHidden:YES];
                    [filterMask setHidden:YES];
                    
                }];
            
            }
            
            break;
        default:
            break;
    }
    
    
    
    
    


}

#pragma mark - 隐藏筛选面板
- (void) dimissFilterPannel1{
    [self.view layoutIfNeeded];
    [UIView animateWithDuration:ANIMATION_DURATION animations:^{
        _filterPannelConstraintHeight.constant = 0;
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        [_filterPannelIndicator setHidden:YES];
        [filterPannelView setHidden:YES];
        [filterMask setHidden: YES];
    }];
    

}

- (void) dimissFilterPannel2{
    [self.view layoutIfNeeded];
    [UIView animateWithDuration:ANIMATION_DURATION animations:^{
        for (NSLayoutConstraint *constraint in self.view.constraints) {
            if(constraint.firstItem == filterMorePannelView && constraint.firstAttribute == NSLayoutAttributeHeight){
                constraint.constant = 0;
            }
        }
        
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        [_filterPannelIndicator setHidden:YES];
        [filterMorePannelView setHidden:YES];
        [filterMask setHidden: YES];
    }];
    
    
}



#pragma mark - tableView数据请求

- (void) initData{

    //行业类型
    
    [ApplicationDelegate.httpRequestEngine postWithPath:@"/houseCategory/industryCategorys.do" json: nil completionHandler:^(MKNetworkOperation *operation) {
        
        
        _industryCategorysArray = [[NSMutableArray alloc] initWithArray:[[operation responseJSON]valueForKey:@"data"]];
        [_industryCategorysArray insertObject:@{@"industryCategoryId":@0,@"categoryName":@"不限",@"sort":@249} atIndex:0];

        
        } errorHandler:^(NSError *error) {
            NSLog(@"Request industryCategorys data ERROR:%@",error.localizedDescription);
        }];
    
    //类型类别
    [ApplicationDelegate.httpRequestEngine postWithPath:@"/houseCategory/typeCategorys.do" json: nil completionHandler:^(MKNetworkOperation *operation) {
        _typeCategorysArray = [[NSMutableArray alloc]initWithArray:[[operation responseJSON] valueForKey:@"data"]];
        
        [_typeCategorysArray insertObject:@{@"typeCategoryId":@7,@"categoryName":@"不限",@"sort":@249} atIndex:0];
        
    } errorHandler:^(NSError *error) {
        NSLog(@"Request industryCategorys data ERROR:%@",error.localizedDescription);
    }];
    
    
    
    //特殊区位；/houseCategory/locationCategorys.do
    
    [ApplicationDelegate.httpRequestEngine postWithPath:@"/houseCategory/locationCategorys.do" json: nil completionHandler:^(MKNetworkOperation *operation) {
        
        _locationCategorysArray = [[NSMutableArray alloc] initWithArray:[[operation responseJSON] valueForKey:@"data"]];
        [_locationCategorysArray insertObject:@{@"specialLocationCategoryId":@0,@"categoryName":@"不限",@"sort":@0} atIndex:0];
        
    } errorHandler:^(NSError *error) {
        NSLog(@"Request industryCategorys data ERROR:%@",error.localizedDescription);
    }];
    
    //项目性质

    [ApplicationDelegate.httpRequestEngine postWithPath:@"/houseCategory/natureCategorys.do" json: nil completionHandler:^(MKNetworkOperation *operation) {
        _projectNatureCategorysArray = [[NSMutableArray alloc]initWithArray:[[operation responseJSON] valueForKey:@"data"]];
        
        [_projectNatureCategorysArray insertObject:@{@"projectNatureCategoryId":@0,@"categoryName":@"不限",@"sort":@0} atIndex:0];
        
    } errorHandler:^(NSError *error) {
        
        NSLog(@"Request industryCategorys data ERROR:%@",error.localizedDescription);
    }];
    
    [self queryHouseData];
    
}




#pragma mark - 根据筛选条件查询数据
- (void) setUpQueryParam {
    //组装查询语句
    /*
    {"pageNumber":1,"pageSize":10,"params":
     
     {"maxRentPrice":1000,"maxBuyPrice":1000,
     "status":1,
     "industryCategoryId":2,
     "maxBuildingArea":500,
     "minBuildingArea":5,
     "maxPrice":10000,"minPrcie":100,
     "projectNatureCategoryId":1,
     "specialLocationCategoryId":1,
     "minModelArea":5,"maxModelArea":500,
     "activityCategoryId":3,
     "typeCategoryId":2}}
     */
    //activityCategoryId  1团购、2团租
    
    
    _queryParam = [[NSMutableDictionary alloc] init];
    
    //团购
   
    [_queryParam setObject:_activityCategoryId forKey:@"activityCategoryId"];
    
    //行业类型
    if(_industCatSelectedIndex != 0)
    [_queryParam setObject:[[_industryCategorysArray objectAtIndex:_industCatSelectedIndex] valueForKey:@"industryCategoryId"] forKey:@"industryCategoryId"];
    
    //类型
    if(_typeCategorysSelectedIndex != 0)
    [_queryParam setObject:[[_typeCategorysArray objectAtIndex:_typeCategorysSelectedIndex] valueForKey:@"typeCategoryId"] forKey:@"typeCategoryId" ];
    
    //状态
    if(_statusCategorysSelectedIndex != 0)
    [_queryParam setObject:[NSNumber numberWithInteger:_statusCategorysSelectedIndex]  forKey:@"status"];

    
    //体量
    if (_buildingAreaSelectedIndex != 0){
        [_queryParam setObject:[[_buildingAreaArray objectAtIndex:_buildingAreaSelectedIndex] valueForKey:@"minBuildingArea"] forKey:@"minBuildingArea"];
        [_queryParam setObject:[[_buildingAreaArray objectAtIndex:_buildingAreaSelectedIndex] valueForKey:@"minBuildingArea"] forKey:@"maxBuildingArea"];
    
    }
    
    //特殊区位
    if (_locationCategorysSelectedIndex != 0)
    [_queryParam setObject:[[_locationCategorysArray objectAtIndex:_locationCategorysSelectedIndex] valueForKey:@"specialLocationCategoryId"] forKey:@"specialLocationCategoryId"];
    
    //售价
    if (_buyPriceSelectedIndex != 0){
        [_queryParam setObject:[[_buyPriceArray objectAtIndex:_buyPriceSelectedIndex] valueForKey:@"maxPrice"] forKey:@"maxPrice"];
        [_queryParam setObject:[[_buyPriceArray objectAtIndex:_buyPriceSelectedIndex] valueForKey:@"maxPrice"] forKey:@"minPrice"];
    }
    
    //户型
    if (_modelAreaSelectedIndex != 0){
        [_queryParam setObject:[[_modelAreaArray objectAtIndex:_modelAreaSelectedIndex] valueForKey:@"minModelArea"] forKey:@"minModelArea"];
        [_queryParam setObject:[[_modelAreaArray objectAtIndex:_modelAreaSelectedIndex] valueForKey:@"maxModelArea"] forKey:@"maxModelArea"];
    }
    //租金
    
    //项目性质
    
    if (_projectNatureSelectedIndex != 0)
    [_queryParam setObject:[[_projectNatureCategorysArray objectAtIndex:_projectNatureSelectedIndex] valueForKey:@"projectNatureCategoryId"] forKey:@"projectNatureCategoryId"];

}
- (void)queryHouseData{
    
    [self setUpQueryParam];
    [ApplicationDelegate.httpRequestEngine postWithPath:@"/house/houseFilterList.do" json:@{@"pageNumber":[NSNumber numberWithInteger: _currentPage+1],@"pageSize":@10,@"params":_queryParam} completionHandler:^(MKNetworkOperation *operation) {
        _currentPage++;
        if (_groupbuyArray==nil) {
            _groupbuyArray = [[NSMutableArray alloc] init];
        }
        
        
        
        if ([[[operation responseJSON] valueForKey:@"data"] isEqual:[NSNull null]]) {
           [_footerViewAcitiviyIndicatorView stopAnimating];
            _footerViewLabel.text = @"没有更多数据!";
        }else{
            [_groupbuyArray addObjectsFromArray:[[operation responseJSON] valueForKey:@"data"]];
            [_tableView reloadData];
            
            [_footerViewAcitiviyIndicatorView stopAnimating];
            _footerViewLabel.text = @"上拉加载更多数据!";
        }
        
        
        _isLoading = NO;
        
    } errorHandler:^(NSError *error) {
        [_footerViewAcitiviyIndicatorView stopAnimating];
        _footerViewLabel.text = @"数据加载失败!";
        _isLoading = NO;
        NSLog(@"ERROR:query group buy with params error:%@",[error localizedDescription]);
    }];
    


}

#pragma mark - 查询按钮 - 确定
- (void) filterMoreOkBtnClick:(id)sender{
    [self dimissFilterPannel2];
    _currentPage = 0;
    [_groupbuyArray removeAllObjects];
    [self queryHouseData];
}

#pragma mark - 查询按钮 - 重置
- (void) filterMoreResetBtnClick:(id)sender{
    [self dimissFilterPannel2];

    _industCatSelectedIndex = 0;//行业类型
    _typeCategorysSelectedIndex = 0;//类型
    _statusCategorysSelectedIndex = 0;//状态
    _buildingAreaSelectedIndex = 0;
    _locationCategorysSelectedIndex = 0;
    _buyPriceSelectedIndex = 0;
    _modelAreaSelectedIndex = 0;
    _rentPriceArraySelectedIndex = 0;
    _projectNatureSelectedIndex = 0;
    _currentPage =0;
    [_groupbuyArray removeAllObjects];
    [self queryHouseData];
}



#pragma mark -tableView的代理方法

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //filterMorePannelTableView1
    if(tableView == filterMorePannelTableView1){
        _filterMoreArraySelectedIndex = indexPath.row;
        [filterMorePannelTableView2 reloadData];
    
    }
    
    if(tableView == filterMorePannelTableView2){
    
        switch (_filterMoreArraySelectedIndex) {
            case 0:
                //不限
                
                break;
            case 1:
                //体量
                //_buildingAreaArray
                _buildingAreaSelectedIndex = indexPath.row;
                break;
                
            case 2:
                //特殊区位
                //_locationCategorysArray;
                _locationCategorysSelectedIndex = indexPath.row;
                
                break;
            case 3:
                //售价
                _buyPriceSelectedIndex = indexPath.row;
                break;
                
            case 4:
                //户型
                _modelAreaSelectedIndex = indexPath.row;
                break;
            case 5:
                //租金
                _rentPriceArraySelectedIndex = indexPath.row;
                break;
            case 6:
                //项目性质
                _projectNatureSelectedIndex = indexPath.row;
                break;
            default:
                
                break;
        }
        
        [filterMorePannelTableView2 reloadData];
    }
    
    
    if(tableView.tag == 2){
        [self dimissFilterPannel1];
        switch (_currentPannelInex) {
            
            case FILTER_INDUST_CAT:
                _industCatSelectedIndex = indexPath.row;
                _currentPage = 0;
                [_groupbuyArray removeAllObjects];
                [self queryHouseData];
                break;
                
            case FILTER_TYPE_CAT:
                _typeCategorysSelectedIndex = indexPath.row;
                _currentPage = 0;
                [_groupbuyArray removeAllObjects];
                [self queryHouseData];
                break;
            case FILTER_STATUS_CAT:
                _statusCategorysSelectedIndex = indexPath.row;
                _currentPage = 0;
                [_groupbuyArray removeAllObjects];
                [self queryHouseData];
                
                break;
            default:
                break;
        }
        
        
    }
    
    
    if(tableView.tag == 1){
    
        KVNGroupbuyDetailViewController *detailViewController = [[KVNGroupbuyDetailViewController alloc] init];
        //detailViewController.houseTitle = [[_groupbuyArray objectAtIndex:indexPath.row] valueForKey:@"houseName"];
        detailViewController.houseId =[[[_groupbuyArray objectAtIndex:indexPath.row] valueForKey:@"houseId"] integerValue];
        [self.navigationController pushViewController:detailViewController animated:YES];
    
    }
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    
    switch (tableView.tag) {
        case 2:
            switch (_currentPannelInex) {
                case FILTER_INDUST_CAT:
                    return [_industryCategorysArray count];
                    break;
                case FILTER_TYPE_CAT:
                    return [_typeCategorysArray count];
                    break;
                case FILTER_STATUS_CAT:
                    return [_houseStatusArray count];
                    break;
                default:
                    return 0;
                    break;
            }
            
            break;
          
        case 3:
           
            return _filterMoreArray.count;
            break;
        
        case 4:
            switch (_filterMoreArraySelectedIndex) {
                case 0:
                    //不限
                    return 0;
                    break;
                case 1:
                    //体量
                    //_buildingAreaArray
                    return [_buildingAreaArray count];
                    break;
                    
                case 2:
                    //特殊区位
                    //_locationCategorysArray;
                    return _locationCategorysArray.count;
                    break;
                case 3:
                    //售价
                    return _buyPriceArray.count;
                    break;
                    
                case 4:
                    //户型
                    return _modelAreaArray.count;
                    break;
                case 5:
                    //租金
                    return _rentPriceArray.count;
                    break;
                case 6:
                    //项目性质
                    return _projectNatureCategorysArray.count;
                    break;
                default:
                    break;
            }
            
            return 0;
            break;
        default:
            return [_groupbuyArray count];
            break;
    }
    

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    
    //筛选条件tableView
    if(tableView.tag == 2)
    {
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FILTER_CELL"];
        if(cell == nil)
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FILTER_CELL"];
        
        switch (_currentPannelInex) {
            case FILTER_INDUST_CAT:
                if(_industCatSelectedIndex == indexPath.row){
                    cell.textLabel.textColor = [UIColor redColor];
                }else{
                    cell.textLabel.textColor = [UIColor blackColor];
                }
                cell.textLabel.text = [[_industryCategorysArray objectAtIndex:indexPath.row] valueForKey:@"categoryName"];
                break;
            
            case FILTER_TYPE_CAT:
                if(_typeCategorysSelectedIndex == indexPath.row){
                    cell.textLabel.textColor = [UIColor redColor];
                }else{
                    cell.textLabel.textColor = [UIColor blackColor];
                }
                cell.textLabel.text = [[_typeCategorysArray objectAtIndex:indexPath.row] valueForKey:@"categoryName"];
                break;
            case FILTER_STATUS_CAT:
                if(_statusCategorysSelectedIndex == indexPath.row){
                    cell.textLabel.textColor = [UIColor redColor];
                }else{
                    cell.textLabel.textColor = [UIColor blackColor];
                }
                cell.textLabel.text = [_houseStatusArray objectAtIndex:indexPath.row];
                break;
                
            default:
                
                break;
        }
        
        
        return cell;
    }
    
    
    if(tableView.tag==3){
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FILTER_CELL"];
        if(cell == nil)
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FILTER_CELL"];
        cell.textLabel.text = [_filterMoreArray objectAtIndex:indexPath.row];
        
        return cell;
    
    
    }
    
    
    if(tableView.tag == 4){
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FILTER_CELL"];
        if(cell == nil)
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FILTER_CELL"];
        
        
        switch (_filterMoreArraySelectedIndex) {
            case 0:
                //不限
                cell.textLabel.text = @"";
                break;
            case 1:
                //体量
                //_buildingAreaArray
                
                if(_buildingAreaSelectedIndex == indexPath.row){
                    cell.textLabel.textColor = [UIColor redColor];
                }else{
                    cell.textLabel.textColor = [UIColor blackColor];
                }
                
                cell.textLabel.text = [[_buildingAreaArray objectAtIndex:indexPath.row] valueForKey:@"name"];
                break;
                
            case 2:
                //特殊区位
                //_locationCategorysArray;
                if(_locationCategorysSelectedIndex == indexPath.row){
                    cell.textLabel.textColor = [UIColor redColor];
                }else{
                    cell.textLabel.textColor = [UIColor blackColor];
                }
                
                cell.textLabel.text = [[_locationCategorysArray objectAtIndex:indexPath.row] valueForKey:@"categoryName"];
                
                break;
            case 3:
                //售价
                if(_buyPriceSelectedIndex == indexPath.row){
                    cell.textLabel.textColor = [UIColor redColor];
                }else{
                    cell.textLabel.textColor = [UIColor blackColor];
                }
                cell.textLabel.text = [[_buyPriceArray objectAtIndex:indexPath.row] valueForKey:@"name"];
                break;
                
            case 4:
                //户型
                if(_modelAreaSelectedIndex == indexPath.row){
                    cell.textLabel.textColor = [UIColor redColor];
                }else{
                    cell.textLabel.textColor = [UIColor blackColor];
                }
                cell.textLabel.text = [[_modelAreaArray objectAtIndex:indexPath.row] valueForKey:@"name"];
                break;
            case 5:
                //租金
                if(_rentPriceArraySelectedIndex == indexPath.row){
                    cell.textLabel.textColor = [UIColor redColor];
                }else{
                    cell.textLabel.textColor = [UIColor blackColor];
                }
                cell.textLabel.text = [_rentPriceArray objectAtIndex:indexPath.row];
                break;
            case 6:
                //项目性质
                if(_projectNatureSelectedIndex == indexPath.row){
                    cell.textLabel.textColor = [UIColor redColor];
                }else{
                    cell.textLabel.textColor = [UIColor blackColor];
                }
                cell.textLabel.text = [[_projectNatureCategorysArray objectAtIndex:indexPath.row] valueForKey:@"categoryName"];
                break;
            default:
                cell.textLabel.text = @"";
                break;
        }
        
        
        return cell;
    }
    
    
    KVNHouseTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"GROUP_BUY_CELL"];
    if(cell == nil)
    {
        cell = [[KVNHouseTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GROUP_BUY_CELL"];
        cell.layer.borderColor = [[UIColor colorWithWhite:0.9 alpha:1] CGColor];
        cell.layer.borderWidth = 0.3;
        switch ([_activityCategoryId intValue]) {
            case 1:
                [cell.indicatorImageView setImage:[UIImage imageNamed:@"index_icon_bulk"]];
                break;
            case 2:
                [cell.indicatorImageView setImage:[UIImage imageNamed:@"index_icon_specialShop"]];
            case 3:
                break;
            default:
                [cell.indicatorImageView setImage:[UIImage imageNamed:@"index_icon_specialShop"]];
                break;
        }
        
        
    }
    

    cell.titleView.text = [[_groupbuyArray objectAtIndex:indexPath.row] valueForKey:@"houseName"];
    cell.valueView1.text =  [[_groupbuyArray objectAtIndex:indexPath.row] valueForKey:@"address"];
    
    NSString *perferentialContent = [[_groupbuyArray objectAtIndex:indexPath.row] valueForKey:@"perferentialContent"];
    if ([perferentialContent isEqual:[NSNull null]]||perferentialContent == nil || [perferentialContent isEqualToString:@""]) {
        perferentialContent = @"   ";
    }
    cell.valueView2.text =  perferentialContent;

    //设置价格
    NSString *priceString = [NSString stringWithFormat:@"%@元/m2", [[_groupbuyArray objectAtIndex:indexPath.row] valueForKey:@"price"]];
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]initWithString:priceString];
    [attrString addAttribute:(id)kCTSuperscriptAttributeName value:@1 range:NSMakeRange(priceString.length - 1, 1)];
    [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(priceString.length - 1, 1)];
    [cell.valueView3 setAttributedText:attrString];
    
    [cell.defaultImageView setImageFromURL:[NSURL URLWithString:[[_groupbuyArray objectAtIndex:indexPath.row] valueForKey:@"defaultImage"]] placeHolderImage:[UIImage imageNamed:@"home_logo"]];
    
    //计算剩余天数
    if([_activityCategoryId intValue]!= 3){
        NSTimeInterval preferentialEndTime =[[[_groupbuyArray objectAtIndex:indexPath.row] valueForKey:@"preferentialEndtime"] doubleValue];
        
        NSDate *preferentialDate = [NSDate dateWithTimeIntervalSince1970:preferentialEndTime];
        
        NSTimeInterval timeInterval =[preferentialDate timeIntervalSinceNow];
        //天数
        if(timeInterval<0){
            [cell.valueView4 setText:@"剩余0天"];
        }else{
            int days = ceil(timeInterval/(24*60*60));
            [cell.valueView4 setText:[NSString stringWithFormat:@"剩余%d天",days]];
        }
        

    }
    

   
    return cell;
}

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{

    return 1;

}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (tableView.tag) {
        case 1:
            return TABLE_VIEW_CELL_HEIGHT;
            break;
            
        default:
            return FILTER_CELL_HEIGHT;
            break;
    }
   
}

#pragma mark --上拉刷新
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
        //假设偏移表格高度r20%进行刷新
    if (_isLoading == NO) {//判断是否处于刷新状态，刷新中不执行
        //取内容高度
        //  如果内容高度大于UItableView高度，取UItableView高度
        //  如果内容高度小于UITableView高度, 取内容高度
        float height = _tableView.contentSize.height>_tableView.bounds.size.height?_tableView.bounds.size.height:_tableView.contentSize.height;
        
        if ((height - _tableView.contentSize.height + _tableView.contentOffset.y)/height > 0.2) {
            //调用上拉刷新方法
            
            [self queryHouseData];
            [_footerViewAcitiviyIndicatorView startAnimating];
            _footerViewLabel.text = @"数据加载中...";
            _isLoading = YES;
        }
        
        if (- _tableView.contentOffset.y /_tableView.bounds.size.height > 0.2) {
            //调用下拉刷新方法
         
            
        }
        
    }

}

@end
